package com.ecarx.module_udisk.adapter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;

import com.ecarx.module_udisk.R;
import com.ecarx.module_udisk.bean.LogBean;

import java.util.List;


public class LogAdapter extends RecyclerView.Adapter<LogAdapter.MyViewHolder> {
    private static final String TAG = "LogAdapter";
    private Context mContext;
    private List<LogBean> logList;

    public LogAdapter(Context mContext) {
        this.mContext = mContext;
    }

    public void setLogList(List<LogBean> logList) {
        this.logList = logList;
        notifyDataSetChanged();
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.item_log, parent, false);
        MyViewHolder vh = new MyViewHolder(view);
        return vh;
    }

    @SuppressLint("ResourceAsColor")
    @Override
    public void onBindViewHolder(MyViewHolder holder, @SuppressLint("RecyclerView") int position) {
        final LogBean bean = logList.get(position);
        holder.tv.setText(bean.getLog());
        if(bean.isSuccess()){
            holder.tv.setTextColor(Color.BLACK);
        }else{
            holder.tv.setTextColor(Color.RED);
        }
    }


    @Override
    public int getItemCount() {
        if(logList == null || logList.size() == 0){
            return 0;
        }
        return logList.size();
    }


    static class MyViewHolder extends RecyclerView.ViewHolder {

        TextView tv;
        public MyViewHolder(View itemView) {
            super(itemView);
            tv = (TextView) itemView.findViewById(R.id.text);
        }

    }
}
